home *** CD-ROM | disk | FTP | other *** search
/ Dr. Windows 3 / dr win3.zip / dr win3 / GRAPHICS / GPT35WIN.ZIP / DEMO / PROB.DEM < prev    next >
Text File  |  1993-05-11  |  23KB  |  793 lines

  1. #
  2. # $Id: prob.demo 3.38.2.32 1992/12/04 18:33:59 woo Exp $
  3. #
  4. # Demo Statistical Functions version 2.3
  5. #
  6. # Permission granted to distribute freely for non-commercial purposes only
  7. #
  8. # Copyright (c) 1991, 1992 Jos van der Woude, jvdwoude@hut.nl
  9.  
  10. pause 0 "                   Statistical Library Demo, version 2.3"
  11. pause 0 ""
  12. pause 0 "          Copyright (c) 1991, 1992, Jos van de Woude, jvdwoude@hut.nl"
  13. pause 0 "Permission granted to distribute freely for non-commercial purposes only"
  14. pause 0 ""
  15. pause 0 ""
  16. pause 0 ""
  17. pause 0 ""
  18. pause 0 ""
  19. pause 0 ""
  20. pause 0 ""
  21. pause 0 ""
  22. pause 0 ""
  23. pause 0 ""
  24. pause 0 ""
  25. pause 0 ""
  26. pause 0 ""
  27. pause 0 ""
  28. pause 0 ""
  29. pause 0 "NOTE: contains 54 plots and consequently takes a lot of time to run"
  30. pause 0 "                      Press Ctrl-C to exit right now"
  31. pause -1 "                      Press Return to start demo ..."
  32.  
  33. save set "defaults.ini"
  34. load "stat.inc"
  35.  
  36. # Arcsinus PDF and CDF
  37. r = 2.0
  38. mu = 0.0
  39. sigma = r / sqrt2
  40. xmin = -r
  41. xmax = r
  42. ymax = 1.1 * r #No mode
  43. set nokey
  44. set zeroaxis
  45. set xrange [xmin : xmax]
  46. set yrange [0 : ymax]
  47. set xlabel "x ->"
  48. set ylabel "probability density ->"
  49. set xtics
  50. set ytics
  51. set format x "%.1f"
  52. set format y "%.1f"
  53. set sample 200
  54. set title "arcsin PDF with r = 2.0"
  55. plot arcsin(x)
  56. pause -1 "Hit return to continue"
  57. set title "arcsin CDF with r = 2.0"
  58. set yrange [0 : 1.1]
  59. plot carcsin(x)
  60. pause -1 "Hit return to continue"
  61.  
  62. # Beta PDF and CDF
  63. #p = 0.5; q = 0.7
  64. #mu = p / (p + q)
  65. #sigma = sqrt(p**q) / ((p + q ) * sqrt(p + q + 1.0))
  66. #xmin = 0.0
  67. #xmax = 1.0
  68. #Mode of beta PDF used
  69. #ymax = (p < 1.0 || q < 1.0) ? 2.0 : 1.1 * beta((p - 1.0)/(p + q - 2.0))
  70. set key
  71. set zeroaxis
  72. #set xrange [xmin : xmax]
  73. #set yrange [0 : ymax]
  74. set xlabel "x ->"
  75. set ylabel "probability density ->"
  76. set xtics
  77. set ytics
  78. set format x "%.1f"
  79. set format y "%.1f"
  80. set sample 100
  81. set title "beta PDF"
  82. plot [0:1] [0:5] p = 0.5, q = 0.7, beta(x) title "p = 0.5, q = 0.7", \
  83.                  p = 5.0, q = 3.0, beta(x) title "p = 5.0, q = 3.0", \
  84.                  p = 0.5, q = 2.5, beta(x) title "p = 0.5, q = 2.5"
  85. pause -1 "Hit return to continue"
  86. set title "incomplete beta CDF"
  87. plot [0:1] [0:1.1] p = 0.5, q = 0.7, cbeta(x) title "p = 0.5, q = 0.7", \
  88.                    p = 5.0, q = 3.0, cbeta(x) title "p = 5.0, q = 3.0", \
  89.                    p = 0.5, q = 2.5, cbeta(x) title "p = 0.5, q = 2.5"
  90. pause -1 "Hit return to continue"
  91.  
  92. # Binomial PDF and CDF
  93. n = 25; p = 0.15
  94. mu = n * p
  95. sigma = sqrt(n * p * (1.0 - p))
  96. xmin = int(mu - 4.0 * sigma)
  97. xmin = xmin < 0 ? 0 : xmin
  98. xmax = int(mu + 4.0 * sigma)
  99. ymax = 1.1 * binom(mu) #Mode of normal PDF used
  100. xinc = ceil((xmax - xmin) / 10)
  101. xinc = xinc > 1 ? xinc : 1
  102. set nokey
  103. set nozeroaxis
  104. set xrange [xmin : xmax]
  105. set yrange [0 : ymax]
  106. set xlabel "k ->"
  107. set ylabel "probability density ->"
  108. set xtics xmin + 0.499, xinc, xmax
  109. set ytics 0, ymax / 10, ymax
  110. set format x "%2.0f"
  111. set format y "%3.2f"
  112. set sample (xmax - xmin) + 1
  113. set title "binomial PDF with n = 25, p = 0.15"
  114. plot binom(x) with steps
  115. pause -1 "Hit return to continue"
  116. set title "binomial CDF with n = 25, p = 0.15"
  117. set yrange [0 : 1.1]
  118. set ytics 0, 1.1 / 10.5, 1.1
  119. plot cbinom(x) with steps
  120. pause -1 "Hit return to continue"
  121.  
  122. # Cauchy PDF and CDF
  123. #a = 0.0; b = 2.0
  124. #cauchy PDF has no moments
  125. #xmin = a - 4.0 * b
  126. #xmax = a + 4.0 * b
  127. #ymax = 1.1 * cauchy(a) #Mode of cauchy PDF used
  128. set key
  129. set zeroaxis
  130. #set xrange [xmin : xmax]
  131. #set yrange [0 : ymax]
  132. set xlabel "x ->"
  133. set ylabel "probability density ->"
  134. set xtics
  135. set ytics
  136. set format x "%.1f"
  137. set format y "%.2f"
  138. set sample 100
  139. set title "cauchy PDF"
  140. plot [-15:15] [0:0.2] a = 0, b = 2, cauchy(x) title "a = 0, b = 2", \
  141.                       a = 0, b = 4, cauchy(x) title "a = 0, b = 4"
  142. pause -1 "Hit return to continue"
  143. set title "cauchy CDF"
  144. plot [-30:30] [0:1.1] a = 0, b = 2, ccauchy(x) title "a = 0, b = 2", \
  145.                       a = 0, b = 4, ccauchy(x) title "a = 0, b = 4"
  146. pause -1 "Hit return to continue"
  147.  
  148. # Chi-square PDF and CDF
  149. #df1 = 4.0
  150. #mu = df1
  151. #sigma = sqrt(2.0 * df1)
  152. #xmin = mu - 4.0 * sigma
  153. #xmin = xmin < 0 ? 0 : xmin
  154. #xmax = mu + 4.0 * sigma
  155. #ymax = 1.1 * (df1 > 2.0 ? chi(df1 - 2.0) : 1.0) #Mode of chi PDF used
  156. set key
  157. set zeroaxis
  158. #set xrange [xmin : xmax]
  159. #set yrange [0 : ymax]
  160. set xlabel "x ->"
  161. set ylabel "probability density ->"
  162. set xtics
  163. set ytics
  164. set format x "%.1f"
  165. set format y "%.2f"
  166. set sample 100
  167. set title "chi-square PDF"
  168. plot [0:15] [0:0.2] df1 = 4, chi(x) title "df = 4", \
  169.                     df1 = 6, chi(x) title "df = 6", \
  170.                     df1 = 8, chi(x) title "df = 8"
  171. pause -1 "Hit return to continue"
  172. set title "chi-square CDF"
  173. plot [0:15] [0:1.1] df1 = 4, cchi(x) title "df = 4", \
  174.                     df1 = 6, cchi(x) title "df = 6", \
  175.                     df1 = 8, cchi(x) title "df = 8"
  176. pause -1 "Hit return to continue"
  177.  
  178. # Erlang PDF and CDF
  179. #lambda = 1.0; n = 2.0
  180. #mu = n / lambda
  181. #sigma = sqrt(n) / lambda
  182. #xmin = mu - 4.0 * sigma
  183. #xmin = xmin < 0 ? 0 : xmin
  184. #xmax = mu + 4.0 * sigma
  185. #ymax = n < 2.0 ? 1.0 : 1.1 * erlang((n - 1.0) / lambda) #Mode of erlang PDF used
  186. set key
  187. set zeroaxis
  188. #set xrange [xmin : xmax]
  189. #set yrange [0 : ymax]
  190. set xlabel "x ->"
  191. set ylabel "probability density ->"
  192. set xtics
  193. set ytics
  194. set format x "%.1f"
  195. set format y "%.1f"
  196. set sample 100
  197. set title "erlang PDF"
  198. plot [0:10] [0:1] lambda = 1, n = 2, erlang(x) title "lambda = 1, n = 2", \
  199.                   lambda = 2, n = 2, erlang(x) title "lambda = 2, n = 2"
  200. pause -1 "Hit return to continue"
  201. set title "erlang CDF"
  202. plot [0:10] [0:1.1] lambda = 1, n = 2, cerlang(x) title "lambda = 1, n = 2", \
  203.                     lambda = 2, n = 2, cerlang(x) title "lambda = 2, n = 2"
  204. pause -1 "Hit return to continue"
  205.  
  206. # Thanks to mrb2j@kelvin.seas.Virginia.EDU for telling us about this.
  207. # Extreme (Gumbel extreme value) PDF and CDF
  208. #alpha = 0.5; u = 1.0
  209. #mu = u + (0.577215665/alpha)   # Euler's constant
  210. #sigma = pi/(sqrt(6.0)*alpha)
  211. #xmin = mu - 4.0 * sigma
  212. #xmax = mu + 4.0 * sigma
  213. #ymax = 1.1 * extreme(u) #Mode of extreme PDF used
  214. set key
  215. set zeroaxis
  216. #set xrange [xmin : xmax]
  217. #set yrange [0 : ymax]
  218. set xlabel "x ->"
  219. set ylabel "probability density ->"
  220. set xtics
  221. set ytics
  222. set format x "%.1f"
  223. set format y "%.2f"
  224. set sample 100
  225. set title "extreme PDF"
  226. plot [-10:10] [0:0.4] alpha = 0.5, u = 1.0, extreme(x) title "alpha = 0.5, u = 1.0", \
  227.                       alpha = 1.0, u = 0.0, extreme(x) title "alpha = 1.0, u = 0.0"
  228. pause -1 "Hit return to continue"
  229. set title "extreme CDF"
  230. plot [-10:10] [0:1.1] alpha = 0.5, u = 1.0, cextreme(x) title "alpha = 0.5, u = 1.0", \
  231.                       alpha = 1.0, u = 0.0, cextreme(x) title "alpha = 1.0, u = 0.0"
  232. pause -1 "Hit return to continue"
  233.  
  234. # F PDF and CDF
  235. #df1 = 5.0; df2 = 9.0
  236. #mu = df2 < 2.0 ? 1.0 : df2 / (df2 - 2.0)
  237. #sigma = df2 < 4.0 ? 1.0 : mu * sqrt(2.0 * (df1 + df2 - 2.0) / (df1 * (df2 - 4.0)))
  238. #xmin = mu - 4.0 * sigma
  239. #xmin = xmin < 0 ? 0 : xmin
  240. #xmax = mu + 4.0 * sigma
  241. #Mode of F PDF used
  242. #ymax = df1 < 3.0 ? 1.0 : 1.1 * f((df1 / 2.0 - 1.0) / (df1 / 2.0 + df1 / df2))
  243. set key
  244. set zeroaxis
  245. #set xrange [xmin : xmax]
  246. #set yrange [0 : ymax]
  247. set xlabel "x ->"
  248. set ylabel "probability density ->"
  249. set xtics
  250. set ytics
  251. set format x "%.1f"
  252. set format y "%.2f"
  253. set sample 100
  254. set title "F PDF"
  255. plot [0:4] [0:0.8] df1 = 5.0, df2 = 9.0, f(x) title "df1 = 5, df2 = 9", \
  256.                    df1 = 7.0, df2 = 6.0, f(x) title "df1 = 7, df2 = 6"
  257. pause -1 "Hit return to continue"
  258. set title "F CDF"
  259. plot [0:4] [0:1.1] df1 = 5.0, df2 = 9.0, cf(x) title "df1 = 5, df2 = 9", \
  260.                    df1 = 7.0, df2 = 6.0, cf(x) title "df1 = 7, df2 = 6"
  261. pause -1 "Hit return to continue"
  262.  
  263. # Gamma PDF and incomplete gamma CDF
  264. #rho = 0.5; lambda = 1.0
  265. #mu = rho / lambda
  266. #sigma = sqrt(rho) / lambda
  267. #xmin = mu - 4.0 * sigma
  268. #xmin = xmin < 0 ? 0 : xmin
  269. #xmax = mu + 4.0 * sigma
  270. #ymax = rho < 1.0 ? 2.0 : 1.1 * g((rho - 1.0) / lambda) #Mode of gamma pdf used
  271. set key
  272. set zeroaxis
  273. #set xrange [xmin: xmax]
  274. #set yrange [0: ymax]
  275. set xlabel "x ->"
  276. set yla